<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>解决跨域问题</title>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
  </head>
  <body>
    <button id="onlyGet">get请求</button>
    <button id="onlyPost">post请求</button>

  </body>
  <script>
    $(document).ready(()=>{
      $('#onlyGet').on('click',function(){
        $.ajax({
          type:'GET',
          url:'http://127.0.0.1/api/get',
          data:{name:'xz',age:'32'},
          success:(res)=>{
            console.log('请求成功',res)
          }
        })
      })

      $('#onlyPost').on('click',function(){
        $.ajax({
          type:'POST',
          url:'http://127.0.0.1/api/post',
          data:{name:'玉骨遥',age:'2023'},
          success:(res)=>{
            console.log('请求成功',res)
          }
        })
      })

    })
  </script>
</html>